class Solution {
    public int minDeletions(String s) {
        int[] a = new int[26];
        char[] cs = s.toCharArray();
        for(char c:cs) a[c - 'a']+=1;

        Set<Integer>h = new HashSet<Integer>();
        int ans = 0;
        for(int i:a){
            if(i != 0){
                while(h.contains(i)){
                    i--;
                    ans++;
                }
                if(i != 0)h.add(i);
            }
        }return ans;
    }
}